<template>
  <div id="list">
    <ul style="padding-left: 0px">      
      <li
        v-for="item in sessions"
        :class="{ active: item.id === currentSessionId }"
        v-on:click="changeCurrentSessionId(item.id)"
      >   
        <img class="avatar" v-bind:src="item.avatar" :alt="item.userName" />
        <el-badge value="new" class="item" v-if="item.hasNew">
          <p class="name">{{ item.userName }}</p>
        </el-badge>
        <p class="name" v-else>{{ item.userName }}</p>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "list",
  data() {
    return {};
  },
  computed: mapState(["sessions", "currentSessionId"]),
  methods: {
    changeCurrentSessionId: function (id) {
      this.$store.commit("changeCurrentSessionId", id);
    },
  },
};
</script>

<style lang="scss" scoped>
#list {
  li {
    padding: 12px 15px;
    border-bottom: 1px solid #292c33;
    cursor: pointer;
    &:hover {
      background-color: rgba(255, 255, 255, 0.03);
    }
  }
  li.active {
    /*注意这个是.不是冒号:*/
    background-color: rgba(255, 255, 255, 0.1);
  }
  .avatar {
    border-radius: 2px;
    width: 30px;
    height: 30px;
    vertical-align: middle;
  }
  .name {
    display: inline-block;
    margin-left: 15px;
  }

  .item {
    margin-top: 10px;
    margin-right: 40px;
  }
}
</style>
